package com.coocaa.internship.controller;

import com.coocaa.internship.common.ResultCode;
import com.coocaa.internship.common.ResultData;
import com.coocaa.internship.pojo.UserLogin;
import com.coocaa.internship.service.serviceImpl.SMSservicelmpl;
import com.github.qcloudsms.httpclient.HTTPException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;

/**
 * @Description:短信验证
 * @Author: 凌贤
 * @Date: 2019-08-04
 * @Time: 16:17
 */

@Controller
public class SMSController {
    @Autowired
    SMSservicelmpl smSservicelmpl;

    @PostMapping("/sendValidateCode")
    @ResponseBody
    public ResultData sendValidateCode(UserLogin userLogin) {
        ResultData resultData = new ResultData();
        try {
            smSservicelmpl.CodeSend(userLogin.getUserPhone());
            resultData.setCode(ResultCode.SUCCESS);
        } catch (HTTPException e) {
            e.printStackTrace();
            resultData.setCode(ResultCode.FAILED);
            resultData.setData(e.getMessage());

        } catch (IOException e) {
            e.printStackTrace();
            resultData.setCode(ResultCode.FAILED);
            resultData.setData(e.getMessage());
        }
        return resultData;
    }
}
